package com.modifiertech.lineage.base;

import com.modifiertech.lineage.BaseConst;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import java.io.File;

public class ConfigHandler {
    public static Configuration config;
    public static boolean isUseMultiBattleRole=false;
    public static double expMinLevel=50d;//每级经验
    public static int attrAddPerLevel=5;//每级属性
    public static int skillPointAddPerLevel=1;//每级技能点
    public static int skillJumpSplashCoolDown=2500;//skillJumpSplashCoolDown
    public static int skillRangeHealthCoolDown=3000;//skillJumpSplashCoolDown

    public static int attrAddPerLevel_StrongAsBull=5;//身强力壮每级提供的血量加成
    public static double attrManaBasic=20.0;   //默认魔法值




    public static double expIncrese=0.1d;//增益
    public static double expIncreseUseMulti=2.0d;//多项式增益
    public static double expRateFromKillingMob=0.5d;//从杀怪物中获得的收益
    public static int leftmodify=-127;
    public static int leftmodify_mana=183;
    public static int leftmodify_mana_orb=255;
    public static int leftmodify_orb=-127;
    public static int leftmodify_levelmain=-87;
    public static int leftmodify_levelins=-67;
    public static int leftmodify_levelframe=-67;
    public static int leftmodify_leveltext=-78;
    public static int leftmodify_healthtext=-120;
    public static int leftmodify_manatext=262;


    public static int topmodify=7;
    public static int topmodify_mana=7;
    public static int topmodify_mana_orb=-13;
    public static int topmodify_orb=-13;
    public static int topmodify_levelmain=-7;
    public static int topmodify_levelins=3;
    public static int topmodify_levelframe=3;
    public static int topmodify_leveltext=-4;
    public static int topmodify_healttext=-22;
    public static int topmodify_manatext=-22;


    public static int healthtextcolor=16777215;
    public static int manatextcolor=16777215;
    public static int leveltextcolor=16777215;
    public static int textureleftmodify=0;
    public static int texturetopmodify=0;
    public static int weightmodify=0;
    public static int heightmodify=0;

    //shorcutSkillIcon
    public static int skill_1_x=185;
    public static int skill_1_y=23;
    public static int skill_1_size=14;
    public static int skill_2_x=199;
    public static int skill_2_y=23;
    public static int skill_2_size=14;
    public static int skill_3_x=213;
    public static int skill_3_y=23;
    public static int skill_3_size=14;
    public static int skill_4_x=227;
    public static int skill_4_y=23;
    public static int skill_4_size=14;
    public static int skill_5_x=241;
    public static int skill_5_y=23;
    public static int skill_5_size=14;
    public static int skill_6_x=213;
    public static int skill_6_y=9;
    public static int skill_6_size=14;
    public static int skill_7_x=227;
    public static int skill_7_y=9;
    public static int skill_7_size=14;
    public static int skill_8_x=241;
    public static int skill_8_y=9;
    public static int skill_8_size=14;

    //


    public static int x=180;
    public static int y=5;
    public static int u=0;
    public static int v=0;
    public static int w=317;
    public static int h=232;

    //
    public static String guiPanelConfig="1500/1500";
    public static int[] guiConfigSeq=new int[]{1500,1500};



    public static void init(File configFile){
        config=new Configuration(configFile);
        load();
        config.load();
        MinecraftForge.EVENT_BUS.register(ChangeListener.class);
    }
    public static void load(){
        isUseMultiBattleRole=loadPropBool("Can player use multi battle Role","Set this to true,if u want player have multi battle role,default:false",isUseMultiBattleRole);
        expMinLevel=loadPropDouble("Base Level Exprience in min level","Base Level Exprience in min level",expMinLevel);
        expIncrese=loadPropDouble("Exp increse per level","Exp increse per level",expIncrese);
        expIncreseUseMulti=loadPropDouble("Exp increse per level use multi","Exp increse per level",expIncreseUseMulti);
        expRateFromKillingMob=loadPropDouble("Exp Rate from killingMob","Exp Rate from killingMob",expRateFromKillingMob);
        leftmodify=loadPropInteger("leftmodify","leftmodify",leftmodify);
        leftmodify_orb=loadPropInteger("leftmodify_orb","leftmodify_orb",leftmodify_orb);
        leftmodify_mana=loadPropInteger("leftmodify_mana","leftmodify_mana",leftmodify_mana);
        leftmodify_mana_orb=loadPropInteger("leftmodify_mana_orb","leftmodify_mana_orb",leftmodify_mana_orb);
        leftmodify_levelmain=loadPropInteger("leftmodify_levelmain","leftmodify_levelmain",leftmodify_levelmain);
        leftmodify_levelins=loadPropInteger("leftmodify_levelins","leftmodify_levelins",leftmodify_levelins);
        leftmodify_levelframe=loadPropInteger("leftmodify_levelframe","leftmodify_levelframe",leftmodify_levelframe);
        leftmodify_leveltext=loadPropInteger("leftmodify_leveltext","leftmodify_leveltext",leftmodify_leveltext);
        leftmodify_healthtext=loadPropInteger("leftmodify_healthtext","leftmodify_healthtext",leftmodify_healthtext);
        //
        topmodify=loadPropInteger("topmodify","topmodify",topmodify);
        topmodify_orb=loadPropInteger("topmodify_orb","topmodify_orb",topmodify_orb);
        topmodify_mana=loadPropInteger("topmodify_mana","topmodify_mana",topmodify_mana);
        topmodify_mana_orb=loadPropInteger("topmodify_mana_orb","topmodify_mana_orb",topmodify_mana_orb);
        topmodify_levelmain=loadPropInteger("topmodify_levelmain","topmodify_levelmain",topmodify_levelmain);
        topmodify_levelins=loadPropInteger("topmodify_levelins","topmodify_levelins",topmodify_levelins);
        topmodify_levelframe=loadPropInteger("topmodify_levelframe","topmodify_levelframe",topmodify_levelframe);
        topmodify_leveltext=loadPropInteger("topmodify_leveltext","topmodify_leveltext",topmodify_leveltext);
        topmodify_healttext=loadPropInteger("topmodify_healttext","topmodify_healttext",topmodify_healttext);
        //
        textureleftmodify=loadPropInteger("textureleftmodify","textureleftmodify",textureleftmodify);
        texturetopmodify=loadPropInteger("texturetopmodify","texturetopmodify",texturetopmodify);
        weightmodify=loadPropInteger("weightmodify","weightmodify",weightmodify);
        heightmodify=loadPropInteger("heightmodify","heightmodify",heightmodify);
        leveltextcolor=loadPropInteger("leveltextcolor","leveltextcolor",leveltextcolor);
        healthtextcolor=loadPropInteger("healthtextcolor","healthtextcolor",healthtextcolor);
        //skillRel
        attrAddPerLevel_StrongAsBull=loadPropInteger("attrAddPerLevel_StrongAsBull","attrAddPerLevel_StrongAsBull",attrAddPerLevel_StrongAsBull);

        //skillCoolDown
        skillJumpSplashCoolDown = loadPropInteger("skillJumpSplashCoolDown","skillJumpSplashCoolDown",skillJumpSplashCoolDown);
        skillRangeHealthCoolDown = loadPropInteger("skillRangeHealthCoolDown","skillRangeHealthCoolDown",skillRangeHealthCoolDown);


        //manaBasic
        attrManaBasic=loadPropDouble("attrManaBasic","attrManaBasic",attrManaBasic);

        //shortcutSkill
        skill_1_x=loadPropInteger("skill_1_x","skill_1_x",skill_1_x);
        skill_1_y=loadPropInteger("skill_1_y","skill_1_y",skill_1_y);
        skill_1_size=loadPropInteger("skill_1_size","skill_1_size",skill_1_size);

        skill_2_x=loadPropInteger("skill_2_x","skill_2_x",skill_2_x);
        skill_2_y=loadPropInteger("skill_2_y","skill_2_y",skill_2_y);
        skill_2_size=loadPropInteger("skill_2_size","skill_2_size",skill_2_size);

        skill_3_x=loadPropInteger("skill_3_x","skill_3_x",skill_3_x);
        skill_3_y=loadPropInteger("skill_3_y","skill_3_y",skill_3_y);
        skill_3_size=loadPropInteger("skill_3_size","skill_3_size",skill_3_size);

        skill_4_x=loadPropInteger("skill_4_x","skill_4_x",skill_4_x);
        skill_4_y=loadPropInteger("skill_4_y","skill_4_y",skill_4_y);
        skill_4_size=loadPropInteger("skill_4_size","skill_4_size",skill_4_size);

        skill_5_x=loadPropInteger("skill_5_x","skill_5_x",skill_5_x);
        skill_5_y=loadPropInteger("skill_5_y","skill_5_y",skill_5_y);
        skill_5_size=loadPropInteger("skill_5_size","skill_5_size",skill_5_size);

        skill_6_x=loadPropInteger("skill_6_x","skill_6_x",skill_6_x);
        skill_6_y=loadPropInteger("skill_6_y","skill_6_y",skill_6_y);
        skill_6_size=loadPropInteger("skill_6_size","skill_6_size",skill_6_size);

        skill_7_x=loadPropInteger("skill_7_x","skill_7_x",skill_7_x);
        skill_7_y=loadPropInteger("skill_7_y","skill_7_y",skill_7_y);
        skill_7_size=loadPropInteger("skill_7_size","skill_7_size",skill_7_size);

        skill_8_x=loadPropInteger("skill_8_x","skill_8_x",skill_8_x);
        skill_8_y=loadPropInteger("skill_8_y","skill_8_y",skill_8_y);
        skill_8_size=loadPropInteger("skill_8_size","skill_8_size",skill_8_size);



        x=loadPropInteger("x","x",x);
        y=loadPropInteger("y","y",y);
        u=loadPropInteger("u","u",u);
        v=loadPropInteger("v","v",v);
        w=loadPropInteger("w","w",w);
        h=loadPropInteger("h","h",h);
        guiPanelConfig=loadPropString("guiPanelConfig","guiPanelConfig",guiPanelConfig);
        //
        String [] spliteGuiPanelConfig=guiPanelConfig.split("/");
        guiConfigSeq=new int[spliteGuiPanelConfig.length];
        for (int i = 0; i < spliteGuiPanelConfig.length; i++) {
            guiConfigSeq[i]=Integer.parseInt(spliteGuiPanelConfig[i]);
        }
        //

        if (config.hasChanged()) {
            config.save();
        }
    }
    public static boolean loadPropBool(String propName, String desc, boolean default_) {
        Property prop = config.get(Configuration.CATEGORY_GENERAL, propName, default_);
        prop.setComment(desc);
        return prop.getBoolean(default_);
    }

    public static double loadPropDouble(String propName, String desc, double default_) {
        Property prop = config.get(Configuration.CATEGORY_GENERAL, propName, default_);
        prop.setComment(desc);
        return prop.getDouble(default_);
    }
    public static int loadPropInteger(String propName, String desc, int default_) {
        Property prop = config.get(Configuration.CATEGORY_GENERAL, propName, default_);
        prop.setComment(desc);
        return prop.getInt(default_);
    }
    public static String loadPropString(String propName, String desc, String default_) {
        Property prop = config.get(Configuration.CATEGORY_GENERAL, propName, default_);
        prop.setComment(desc);
        return prop.getString();
    }

    public static class ChangeListener {
        @SubscribeEvent
        public static void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent eventArgs) {
            if (eventArgs.getModID().equals(BaseConst.MODID)) {
                load();
            }
        }
    }
}
